<template>
  <div class="product-detail">
    <!-- 轮播 -->
    <detail-swipe :banner="banner"></detail-swipe>

    <!--服务  -->
    <service></service>

    <!-- 商品标题 -->
    <div class="title">
      <h2>{{ info.name }}</h2>
      <p class="desc">{{ info.goods_brief }}</p>
      <p class="price">{{ info.retail_price | price }}</p>
    </div>

    <!-- 参数规格选择 -->
    <van-cell title="请选择规格数量" is-link @click="showAdd" />

    <!-- 商品详情参数 -->
    <goods-param :attr="attribute" :cont="info.goods_desc"></goods-param>

    <!-- 常见问题 -->
    <issue :issue="issue"></issue>

    <!-- 大家都在看 -->
    <people-see :goodsid="$route.params.id"></people-see>

    <!-- 加入购物车 -->
    <add-cart :info="productList" :goods="productList.id"></add-cart>

    <!-- 加入购物车规格 -->
    <goods-sku :info="info"></goods-sku>

    <!-- 返回按钮 -->
    <div class="back-btn" @click="back">
      <van-icon name="arrow-left" />
    </div>
  </div>
</template>

<script>
import { GetDetailData } from "@/request/api";
import GoodsParam from "./children/GoodsParam";
import DetailSwipe from "./children/DetailSwipe";
import Issue from "./children/Issue";
import PeopleSee from "./children/PeopleSee";
import Service from "@/components/common/Service";
import AddCart from "./children/AddCart";
import GoodsSku from "./children/GoodsSku";
export default {
  components: {
    GoodsParam,
    DetailSwipe,
    Issue,
    PeopleSee,
    Service,
    AddCart,
    GoodsSku
  },
  data() {
    return {
      // 轮播数组
      banner: [],
      // 商品信息
      info: {},
      // 商品参数
      attribute: [],
      // 常见问题数组
      issue: [],
      productList: {}
    };
  },
  methods: {
    back() {
      this.$router.back(-1);
    },
    showAdd() {
      this.$store.commit("changeShowAddCart", true);
    }
  },
  created() {
    GetDetailData({
      id: this.$route.params.id
      // id: "1009024",
    }).then(res => {
      console.log(res);
      this.banner = res.data.gallery;
      this.info = res.data.info;
      this.attribute = res.data.attribute;
      this.issue = res.data.issue;
      this.productList = res.data.productList[0];
    });
  }
};
</script>

<style lang="less" scoped>
.product-detail {
  background-color: #f4f4f4;
  margin-bottom: 50px;
  .title {
    background-color: #fff;
    text-align: center;
    padding: 20px 0;
    h2 {
      font-weight: normal;
      font-size: 24px;
      margin: 10px 0;
    }
    .desc {
      color: #666;
      font-size: 14px;
      margin: 10px;
    }
    .price {
      color: #8b0000;
      margin: 10px;
    }
  }
  .van-cell {
    border-top: 1px solid #ccc;
    margin-bottom: 15px;
  }
  .back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.1);
    // border: solid 1px rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    .van-icon {
      color: #fff;
    }
  }
}
</style>
